<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <link rel="stylesheet" href="../../css/my.css">
</head>
<body >
     <!-- 导航栏 -->
     <nav class="ui segment top attached my-shadow-small">
        <div class="ui container">
            <div class="ui menu stackable">
                <div class="item my-font-max my-font-blod my-font-dark">
                    Admin
                </div>
                <a href="/admin/blog/" class="item my-font-light my-font-blod my-font-large active"><i class="icon book"></i>博客</a>
                <a href="/admin/type/" class="item my-font-light my-font-blod my-font-large"><i class="icon flag"></i>分类及标签</a>
                               
                <div class="right menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img class="ui avatar image" src="https://picsum.photos/100/100.jpg">
                                iron-5
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a class="item" href="/admin/logout">注销 </a>
                        </div>
                    </div>
    
                </div>
            </div>
        </div>
    </nav>
    <!-- 二级菜单 -->
    <div class="ui menu attached pointing" >
        <div class="ui container">
            <a  class="item" href="/admin/blog/publish">发布</a>
            <a  class="item active">管理</a>
        </div>
    
    </div>
    
    <div class="my-container-max" id="blogList">
        <div  class="ui form segment top attached" >
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field my-tb-margin-small">
                    <div class="ui labeled action input">
                        <div class="ui type selection dropdown" id="#selection">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item"  >错误日志</div>
                            </div>
                        </div>
                        <button class="ui clear button" id="clear">清除</button>
                    </div>
                </div>
                <div class="field">
                
                    <select name="" id="" class="ui search dropdown" multiple>
                        <option value="">标签</option>
                        <option value="1">选项2</option>
                        <option value="2">选项3</option>
                    </select>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" name="isRecommend" id="isRecommend">
                        <label for="isRecommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button class="ui button basic teal my-lr-margin-small" type="button" id="search-btn" ><i class="icon search"></i>搜索</button>
                </div>
            </div>
        </div>
        <input type="hidden" name="page">
        <!-- 表格 -->
        <div class="ui segment attached">
            <table class="ui table celled stackable"  >
                <thead>
                <tr>
                    <th></th>
                    <th >标题</th>
                    <th>类型</th>
                    <th>更新时间</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>浏览量</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(blog,index) in blogs" :key="blog.updateTime">
                    <td>{{index+1}}</td>
                    <td>{{blog.title}}</td>
                    <td>{{blog.type.typeName}}</td>
                    <td>{{blog.updateTime}}</td>
                    <td>{{blog.isRecommended?'是':'否'}}</td>
                    <td>{{blog.isPublished?'已发布':'草稿'}}</td>
                    <td>{{blog.viewCount}}</td>
                    <td>
                        <a  class="ui greeen button mini" @click="edit(blog)">编辑</a>
                        <a  class="ui red button mini" @click="deleteBlog(blog)">删除</a>
                    </td>
                </tr>

                </tbody>
                <!-- 下面的按钮 -->
                <tfoot>
                <tr>
                    <th colspan="8">
                       
                           
                                <div class="ui pagination menu teal">
                                    <a class=" item">
                                        上一页
                                    </a>
                                    <a class="active item">
                                        1
                                    </a>
                                    <div class="disabled item">
                                        ...
                                    </div>
                                    <a class="item">
                                        10
                                    </a>
                                    <a class=" item">
                                        下一页
                                    </a>
                                </div>
                                <a  class="ui teal button basic right floated" href="/admin/blog/publish">新增</a>
                        
                        
                    </th>
                </tr>
                </tfoot>
            </table>
            <!-- <div class="ui success message" th:unless="${#strings.isEmpty(msg)}">
                <i class="close icon" id="close"></i>
                <div class="header">提示：</div>
                <p th:text="${msg}"></p>
            </div> -->
        </div>
    </div>
   

<br>

    <script src="../../js/jquery-3.5.1.min.js"></script>
    <script src="../../semanticUI/semantic.min.js"></script>
    <script>


    </script>
     <script>

         const blogList = new Vue({
             el: "#blogList",
             data:{
                page:'',
                 blogs:''
             },
             methods:{
                getBlogs(){
                    let _this = this;
                    axios.get("/admin/blog/getBlogs").then(
                        function(response){
                            _this.page=response.data;
                            _this.blogs = response.data.content;
                        }
                    )
                },
                 deleteBlog(blog){
                     let _this = this;
                     axios.post("/admin/blog/delete",blog).then(
                         function(response){
                             _this.getBlogs();
                         }
                     )
                 },
                 edit(blog){
                    console.log(blog);
                     let _this = this;
                     axios.post("/admin/blog/edit",blog).then(
                         function(response){
                             window.location.href = "/admin/blog/publish"
                         }
                     )
                 }
             },
             mounted(){
                 this.getBlogs();
             }
         })
         $(".ui.dropdown").dropdown();
         $('#clear')
             .on('click', function (){
                 $('.ui.dropdown').dropdown('clear');
             })
     </script>
</body>
</html>